<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        //第一步：接收Form表单数据，通常以POST方式接收
        var_dump($_POST);
        var_dump($_GET);
        $uname=$_POST["uname"];
        $upwd=$_POST["upwd"];
        echo $uname.",".$upwd;
        //第二步：操作数据并返回值 （查询、插入、更新、删除）
        //1、
        $link=  mysqli_connect("localhost", "root", "");
        mysqli_select_db($link, "nhcar");
        mysqli_set_charset($link, "utf8");
        //2、
        $sql="SELECT * FROM users WHERE uname='$uname' AND upwd='$upwd'";
        $result=  mysqli_query($link, $sql);
        var_dump($result); 
        
        //第三步：处理返回结果
        $row=mysqli_fetch_row($result);
        var_dump($row);
//        exit();
        if($row){
            $uid=$row[0];
            $uname=$row[1];
            setcookie("uid",$uid,time()+60*60*24*7);
            setcookie("uname",$uname,time()+60*60*24*7);
           //header 页面跳转
           //成功跳转到首页
//           header ( "Location:index.php");  
            echo "<script>alert('登录成功！');location.href='index.php'</script>";
        }else{
          //失败继续注册 
//           header ( "Location:register.php");  
            echo "<script>alert('登录失败！请前往注册！');location.href='regiser.php'</script>";
        }
        ?>
    </body>
</html>
